<!DOCTYPE html>
<html>
<head>
    

    
<!-- Tencent Speed -->
<script>var _speedMark = new Date()</script>
<!-- End Tencent Speed -->
<!-- Tencent Analysis -->
<script async src="//tajs.qq.com/stats?sId=65074773"></script>
<!-- End Tencent Analysis -->


    



    <meta charset="utf-8">
    
    
    
    <title>DFS 和 BFS | 阿喜的博客 | Blog of lfxiui</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="JavaScript,前端">
    <meta name="description" content="DFS 和 BFS什么是 DFS 和 BFS DFS: 深度优先搜索，顺着被搜索数据结构的关系链，不断往下级搜索，直到尽头，再返回上级往另一个下级继续搜索，直到搜索完成。通过递归实现，不断重复往下搜索，且每个节点只会访问一次。常用于粗暴的遍历搜索。  BFS: 广度优先搜索，顺着被搜索数据结构的关系链，逐层往下搜索，先遍历每一层下的子节点，再往下层继续搜索。通过队列实现，将下一层需要遍历的数据存入">
<meta name="keywords" content="JavaScript,前端">
<meta property="og:type" content="article">
<meta property="og:title" content="DFS 和 BFS">
<meta property="og:url" content="http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/index.html">
<meta property="og:site_name" content="阿喜的博客">
<meta property="og:description" content="DFS 和 BFS什么是 DFS 和 BFS DFS: 深度优先搜索，顺着被搜索数据结构的关系链，不断往下级搜索，直到尽头，再返回上级往另一个下级继续搜索，直到搜索完成。通过递归实现，不断重复往下搜索，且每个节点只会访问一次。常用于粗暴的遍历搜索。  BFS: 广度优先搜索，顺着被搜索数据结构的关系链，逐层往下搜索，先遍历每一层下的子节点，再往下层继续搜索。通过队列实现，将下一层需要遍历的数据存入">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-04-23T03:55:45.534Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="DFS 和 BFS">
<meta name="twitter:description" content="DFS 和 BFS什么是 DFS 和 BFS DFS: 深度优先搜索，顺着被搜索数据结构的关系链，不断往下级搜索，直到尽头，再返回上级往另一个下级继续搜索，直到搜索完成。通过递归实现，不断重复往下搜索，且每个节点只会访问一次。常用于粗暴的遍历搜索。  BFS: 广度优先搜索，顺着被搜索数据结构的关系链，逐层往下搜索，先遍历每一层下的子节点，再往下层继续搜索。通过队列实现，将下一层需要遍历的数据存入">
    
        <link rel="alternate" type="application/atom+xml" title="阿喜的博客" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">lfxiui</h5>
          <a href="mailto:806941929@qq.com" title="806941929@qq.com" class="mail">806941929@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                分类
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/lfxiui" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://www.weibo.com/" target="_blank" >
                <i class="icon icon-lg icon-weibo"></i>
                微博
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/custom"  >
                <i class="icon icon-lg icon-link"></i>
                测试
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">DFS 和 BFS</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">DFS 和 BFS</h1>
        <h5 class="subtitle">
            
                <time datetime="2020-04-23T03:52:49.273Z" itemprop="datePublished" class="page-time">
  2020-04-23
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/算法/">算法</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/算法/面试题/">面试题</a></li></ul></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#DFS-和-BFS"><span class="post-toc-number">1.</span> <span class="post-toc-text">DFS 和 BFS</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#什么是-DFS-和-BFS"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">什么是 DFS 和 BFS</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#搜索树节点"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">搜索树节点</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#DFS"><span class="post-toc-number">1.2.1.</span> <span class="post-toc-text">DFS</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#BFS"><span class="post-toc-number">1.2.2.</span> <span class="post-toc-text">BFS</span></a></li></ol></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-DFS 和 BFS"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">DFS 和 BFS</h1>
        <div class="post-meta">
            <time class="post-time" title="2020-04-23 11:52:49" datetime="2020-04-23T03:52:49.273Z"  itemprop="datePublished">2020-04-23</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/算法/">算法</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/算法/面试题/">面试题</a></li></ul></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h1 id="DFS-和-BFS"><a href="#DFS-和-BFS" class="headerlink" title="DFS 和 BFS"></a>DFS 和 BFS</h1><h2 id="什么是-DFS-和-BFS"><a href="#什么是-DFS-和-BFS" class="headerlink" title="什么是 DFS 和 BFS"></a>什么是 DFS 和 BFS</h2><ul>
<li><p><strong>DFS:</strong> 深度优先搜索，顺着被搜索数据结构的关系链，不断往下级搜索，直到尽头，再返回上级往另一个下级继续搜索，直到搜索完成。通过递归实现，不断重复往下搜索，且每个节点只会访问一次。常用于粗暴的遍历搜索。</p>
</li>
<li><p><strong>BFS:</strong> 广度优先搜索，顺着被搜索数据结构的关系链，逐层往下搜索，先遍历每一层下的子节点，再往下层继续搜索。通过队列实现，将下一层需要遍历的数据存入队列，再逐个访问。常用于寻找最短路径的搜索。</p>
</li>
</ul>
<h2 id="搜索树节点"><a href="#搜索树节点" class="headerlink" title="搜索树节点"></a>搜索树节点</h2><p>这里通过一个搜索树节点的实例来学习 DFS 和 BFS 的使用。</p>
<blockquote>
<p>分别用 DFS 和 BFS 实现一个函数，传入一个树型结构的数据和要搜索节点的 ID，返回这个 ID 对应的树节点。</p>
</blockquote>
<p>数据结构:<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> tree = &#123;    </span><br><span class="line">  id: <span class="string">'1'</span>,    </span><br><span class="line">  label: <span class="string">'first'</span>,    </span><br><span class="line">  children: [        </span><br><span class="line">    &#123;            </span><br><span class="line">      id: <span class="string">'2'</span>,            </span><br><span class="line">      label: <span class="string">'second'</span>        </span><br><span class="line">    &#125;,        </span><br><span class="line">    &#123;            </span><br><span class="line">      id: <span class="string">'3'</span>,            </span><br><span class="line">      label: <span class="string">'third'</span>,            </span><br><span class="line">      children: [                </span><br><span class="line">        &#123;                    </span><br><span class="line">          id: <span class="string">'4'</span>,                    </span><br><span class="line">          label: <span class="string">'fourth'</span>                </span><br><span class="line">        &#125;,                </span><br><span class="line">        &#123;                    </span><br><span class="line">          id: <span class="string">'5'</span>,                    </span><br><span class="line">          label: <span class="string">'fifth'</span>                </span><br><span class="line">        &#125;            </span><br><span class="line">      ]        </span><br><span class="line">    &#125;    </span><br><span class="line">  ] </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="DFS"><a href="#DFS" class="headerlink" title="DFS"></a>DFS</h3><blockquote>
<p>《啊哈!算法》中有介绍到，深度游戏搜索要解决的是下一步应该怎么做。当我们遍历到一个节点时，首先要判断节点是否是我们要搜索的(节点 ID 是否等于传入的 ID 参数)，是的话返回该节点；不是的话，判断是否有子节点，没有子节点则返回 null；有子节点，则遍历子节点并递归搜索子节点；在遍历时判断递归返回的结果是否为 null，是则继续递归下一个子节点，否则返回搜索到的节点。</p>
</blockquote>
<p>例如：当我们从上面的树中搜索 ID 为 4 的节点时，先判断<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (rootNode.id === id)</span><br></pre></td></tr></table></figure></p>
<p>是则返回节点，不是则判断它是否有子节点<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (rootNode.children)</span><br></pre></td></tr></table></figure></p>
<p>没有子节点返回 null，有则遍历递归子节点<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; rootNode.children.length; i++) &#123;</span><br><span class="line">  <span class="keyword">let</span> node = findNodeById(rootNode.children[i], id)</span><br><span class="line">    <span class="comment">// 如果 node 不为空返回</span></span><br><span class="line">    <span class="keyword">if</span> (node) &#123;</span><br><span class="line">      <span class="keyword">return</span> node</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>完整代码如下:<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 深度优先搜索遍历</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * @param &#123;*&#125; rootNode 树</span></span><br><span class="line"><span class="comment"> * @param &#123;*&#125; id 要搜索的 id</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">dfs</span>(<span class="params">rootNode, id</span>) </span>&#123;</span><br><span class="line">  <span class="comment">// 判断是否结果</span></span><br><span class="line">  <span class="keyword">if</span> (rootNode.id === id) &#123;</span><br><span class="line">    <span class="keyword">return</span> rootNode</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// 有子节点，搜索子节点</span></span><br><span class="line">  <span class="keyword">if</span> (rootNode.children) &#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; rootNode.children.length; i++) &#123;</span><br><span class="line">      <span class="keyword">let</span> node = findNodeById(rootNode.children[i], id)</span><br><span class="line">      <span class="comment">// 如果 node 不为空返回</span></span><br><span class="line">      <span class="keyword">if</span> (node) &#123;</span><br><span class="line">        <span class="keyword">return</span> node</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">null</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="BFS"><a href="#BFS" class="headerlink" title="BFS"></a>BFS</h3><blockquote>
<p>广度优先搜索，就是逐层遍历该层所有的子节点，将子节点存入队列中，再通过遍历队列，找到要搜索的节点。先从队列中取到头节点，判断它是否为要搜索的子节点，是则返回节点；否则判断是否有子节点，没有子节点则将其出队；有子节点，遍历子节点，将所有子节点存入队列，再将其出队；然后搜索队列的下一个节点。通过队列和遍历子节点，实现逐层遍历树的一个顺序。</p>
</blockquote>
<p>例如：当我们从上面的树中搜索 ID 为 4 的节点时，先将父节点放入队列<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 把树放入队列</span></span><br><span class="line">arr[tail] = rootNode</span><br><span class="line"><span class="comment">// 下一个入队位置</span></span><br><span class="line">tail ++</span><br></pre></td></tr></table></figure></p>
<p>然后开始遍历队列<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span>(head &lt; tail)</span><br></pre></td></tr></table></figure></p>
<p>先判断列头的节点是不是目标节点，不是再将其子节点存入队列并出队，再继续遍历队列<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (arr[head].id === id) &#123;</span><br><span class="line">  <span class="keyword">return</span> arr[head]</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 子节点加入队列</span></span><br><span class="line"><span class="keyword">if</span> (arr[head].children) &#123;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; arr[head].children.length; i ++) &#123;</span><br><span class="line">    arr[tail] = arr[head].children[i]</span><br><span class="line">    tail ++</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 出队</span></span><br><span class="line">head ++</span><br></pre></td></tr></table></figure></p>
<p>完整代码如下：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 广度优先搜索遍历</span></span><br><span class="line"><span class="comment"> * @param &#123;*&#125; rootNode 树</span></span><br><span class="line"><span class="comment"> * @param &#123;*&#125; id 要搜索的节点 id</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">bfs</span>(<span class="params">rootNode, id</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> arr = []</span><br><span class="line">  <span class="keyword">let</span> head = <span class="number">0</span>, tail = <span class="number">0</span></span><br><span class="line">  <span class="comment">// 把树放入队列</span></span><br><span class="line">  arr[tail] = rootNode</span><br><span class="line">  <span class="comment">// 下一个入队位置</span></span><br><span class="line">  tail ++</span><br><span class="line">  <span class="keyword">while</span>(head &lt; tail) &#123;</span><br><span class="line">    <span class="keyword">if</span> (arr[head].id === id) &#123;</span><br><span class="line">      <span class="keyword">return</span> arr[head]</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 子节点加入队列</span></span><br><span class="line">    <span class="keyword">if</span> (arr[head].children) &#123;</span><br><span class="line">      <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; arr[head].children.length; i ++) &#123;</span><br><span class="line">        arr[tail] = arr[head].children[i]</span><br><span class="line">        tail ++</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 出队</span></span><br><span class="line">    head ++</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">null</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-04-23T03:55:45.534Z" itemprop="dateUpdated">2020-04-23 11:55:45</time>
</span><br>


        
        大家有问题或建议的话可以评论或者用邮箱与我交流~<a href="/2020/04/23/DFS 和 BFS/" target="_blank" rel="external">http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/</a>
        
    </div>
    
    <footer>
        <a href="http://lfxiui.gitee.io">
            <img src="/img/avatar.jpg" alt="lfxiui">
            lfxiui
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/前端/">前端</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/&title=《DFS 和 BFS》 — 阿喜的博客&pic=http://lfxiui.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/&title=《DFS 和 BFS》 — 阿喜的博客&source=尘世中一个迷途的小码农" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《DFS 和 BFS》 — 阿喜的博客&url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/&via=http://lfxiui.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between flex-row-reverse">
  

  
    <div class="waves-block waves-effect next">
      <a href="/2020/03/09/v-show 和 v-if 遇到的坑/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">v-show 和 v-if 遇到的坑</h4>
      </a>
    </div>
  
</nav>



    


<section class="comments" id="comments">
    <div id="disqus_thread"></div>
    <script>
    var disqus_shortname = 'true';
    lazyScripts.push('//' + disqus_shortname + '.disqus.com/embed.js')
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</section>













</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.png" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/img/wechat.png" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>lfxiui &copy; 2015 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/&title=《DFS 和 BFS》 — 阿喜的博客&pic=http://lfxiui.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/&title=《DFS 和 BFS》 — 阿喜的博客&source=尘世中一个迷途的小码农" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《DFS 和 BFS》 — 阿喜的博客&url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/&via=http://lfxiui.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://lfxiui.gitee.io/2020/04/23/DFS 和 BFS/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = 'Waiting...';
            clearTimeout(titleTime);
        } else {
            document.title = 'Running...';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
